package com.mymoney.web.utils;

import javax.servlet.ServletRequest;
import javax.ws.rs.core.SecurityContext;

import com.mymoney.auth.DeviceContext;
import com.mymoney.persistence.PersistenceContext;

/**
 * 
 * @author yavor.gologanov
 *
 */
public class RequestHelper {

	/**
	 * 
	 * @param request
	 * @return
	 */
	public static PersistenceContext getPersistenceContext(ServletRequest request) {
		
		String attrName = PersistenceContext.class.getCanonicalName();
		return (PersistenceContext) request.getAttribute(attrName);
		
	}

	/**
	 * 
	 * @param request
	 * @return
	 */
	public static SecurityContext getSecurityContext(ServletRequest request) {
		
		String attrName = SecurityContext.class.getCanonicalName();
		return (SecurityContext) request.getAttribute(attrName);
		
	}
		
	public static DeviceContext getDeviceContext(ServletRequest request) {
		
		String attrName = DeviceContext.class.getCanonicalName();
		return (DeviceContext) request.getAttribute(attrName);
		
	}
	
	/**
	 * 
	 * @param request
	 * @param context
	 */
	public static void setPersistenceContext(ServletRequest request, PersistenceContext context) {
		
		String attrName = PersistenceContext.class.getCanonicalName();
		request.setAttribute(attrName, context);
		
	}

	/**
	 * 
	 * @param request
	 * @param context
	 */
	public static void setSecurityContext(ServletRequest request, SecurityContext context) {
		
		String attrName = SecurityContext.class.getCanonicalName();
		request.setAttribute(attrName, context);
	}
			
}
